/*
 * KKEvent.h
 *
 *  Created on: 2013-9-15
 *      Author: wanghua
 */

#ifndef KKEVENT_H_
#define KKEVENT_H_

#include "cocos2d.h"
#include "KKEventAction.h"

USING_NS_CC;

using namespace std;

class KKEventHandler: public CCObject {
public:

	KKEventHandler() {
		target = NULL;
		selector = NULL;
	}
	;

	virtual ~KKEventHandler() {
		target = NULL;
		selector = NULL;
	}
	;

	CCObject* target;
	SEL_CallFuncND selector;

	inline void handle(CCNode* target, void* args) {
		(this->target->*selector)(target, args);
	}
};

typedef KKDictionary<std::string, KKEventHandler*> KKFuncDictionary;

typedef KKMutableArray<KKEventAction*> KKEventActionArray;

class KKEvent: public cocos2d::CCObject {
private:
	;CC_SYNTHESIZE(string,m_name,Name)
	;CC_SYNTHESIZE(KKEventActionArray*,m_actions,Actions)
	;CC_SYNTHESIZE(KKEventHandler*,m_eventHandler,EventHandler)
	;
public:
	KKEvent();
	virtual ~KKEvent();

	static KKEvent* eventWithXml(TiXmlElement* element);

	bool initWithXml(TiXmlElement* element);

	void fire(KKEventActionArgs* args);
};
typedef KKDictionary<string, KKEvent*> KKEventDictionary;

#endif /* KKEVENT_H_ */
